(function() {

	var panelFunction;
	if (typeof this.panelFunction === 'undefined') {
		panelFunction = this.panelFunction = {};
	} else {
		panelFunction = this.panelFunction;
	}

	panelFunction.renderAsset = function(value, type) {
		
		var asset;
		
		$.ajax({
			url : "../rest/asset/get",
			type : "POST",
			dataType : "json",
			data : {
				paramType: type,
				paramValue: value,
				result : "{\"flag\":0,\"properties\":{\"ASSET.RCSUNDERLYINGPRODUCT\":[{\"value\":\"46627750\",\"begin_date\":\"2012-09-01 10:46:14\"}],\"ASSET.LSEOPOL\":[{\"value\":\"XAFR\",\"meaning\":\"ALTERNATIVA FRANCE\",\"begin_date\":\"2012-09-03 05:28:53\"}],\"COMMODITY.BTUPERBARREL\":[{\"value\":\"100\"}],\"CLASSIFICATIONSCHEME\":[{\"value\":\"NMJE\",\"meaning\":\"NMJE\",\"begin_date\":\"2012-08-31 02:51:52\",\"type\":\"ASSET.ASSETROOTMAP\",\"displayName\":\"ASSET ROOT MAP\"},{\"value\":\"Y\",\"meaning\":\"Yes\",\"begin_date\":\"2012-09-03 05:29:15\",\"type\":\"ASSET.POL\",\"displayName\":\"POL\"},{\"value\":\"OPT\",\"meaning\":\"Option\",\"begin_date\":\"2012-09-03 05:42:01\",\"type\":\"ASSET.RCSASSETCLASS\",\"displayName\":\"RCS ASSET CLASS\"},{\"value\":\"3\",\"meaning\":\"Lowest priority entities, order not important.\",\"begin_date\":\"2012-08-30 05:03:45\",\"type\":\"ASSET.SEARCHRANKING\",\"displayName\":\"SEARCH RANKING\"}],\"ASSET.RIC\":[{\"value\":\"TESTCO01\",\"begin_date\":\"2012-08-30 05:03:45\"}],\"ASSET.RETIREDATE\":[{\"value\":\"01-MAR-14\"}],\"ASSET.SEDOL\":[{\"value\":\"4567653\",\"begin_date\":\"2012-09-03 05:20:47\"}],\"ASSET.PRIMARYCHAIN.RIC\":[{\"value\":\"0#LCO:\"}],\"LOCATIONS\":[{\"value\":\"AAR\",\"meaning\":\"Aarhus\",\"id\":388,\"type\":\"ASSET.PRODUCTIONLOCATION\",\"displayName\":\"PRODUCTION LOCATION\"},{\"value\":\"AAB\",\"meaning\":\"Arrabury QL\",\"id\":384,\"type\":\"ASSET.DELIVERYLOCATION\",\"displayName\":\"DELIVERY LOCATION\"}],\"ASSET.TRADES.COMMONNAME\":[{\"value\":\"Burgundy AB\"}],\"ASSET.RELATEDPAGE.RIC\":[{\"value\":\"ADD.L\"}],\"ASSET.UNDERLYINGASSET.CATEGORY\":[{\"value\":\"Alfalfa Hay\",\"meaning\":\"Alfalfa Hay\",\"id\":2784}],\"ASSET.PRIMARYCHAIN\":[{\"value\":\"67641787\",\"begin_date\":\"2012-09-01 08:46:22\"}],\"ASSET.RATINGASSET\":[{\"value\":\"Y\"}],\"TICKLADDER\":[{\"not_applicable_flag\":\"N\",\"lhe_references_nda_id\":9,\"name\":\"TICK LADDER D\",\"effective_from\":\"08-AUG-12\",\"effective_to\":\"19-SEP-12\",\"cla_price_type_nda_id\":2000070107,\"value\":\"ORDER\",\"meaning\":\"Order price\",\"begin_date\":\"01-SEP-12\"}],\"CRSUNIT\":[{\"id\":2000069955,\"value\":\"D\",\"meaning\":\"Wet Volume To Energy\",\"factor\":\"1.23\"},{\"id\":2000069959,\"value\":\"F\",\"meaning\":\"Dry Volume to Wet Volume\",\"factor\":\".4\"}],\"ASSET.ASSETSTATE\":[{\"value\":\"AC\",\"meaning\":\"Active\",\"id\":41}],\"NAME\":[{\"value\":\"10\",\"begin_date\":\"2012-08-31 09:48:14\",\"type\":\"ASSET.BRIDGEVEHICLE\",\"displayName\":\"BRIDGE VEHICLE\"},{\"value\":\"TEST Common name\",\"begin_date\":\"2012-08-30 12:01:37\",\"type\":\"ASSET.COMMONNAME\",\"displayName\":\"COMMON NAME\"},{\"value\":\"search display name\",\"begin_date\":\"2012-09-01 08:49:34\",\"type\":\"ASSET.SEARCHDISPLAYNAME\",\"displayName\":\"SEARCH DISPLAY NAME\"}],\"ASSET.TRADES\":[{\"value\":\"15882580\",\"begin_date\":\"2012-08-30 11:47:40\"}],\"COMMODITY.PRICINGUNIT\":[{\"value\":\"0.1 TONNES\",\"meaning\":\"0.1 TONNES\",\"id\":1000033100}],\"ASSET.TYPE\":[{\"value\":\"COMMODITY\"}],\"COMMODITY.BARRELSPERTON\":[{\"value\":\"6\"}],\"IDENTIFIER\":[{\"value\":\"TEST_VALUE_10\",\"begin_date\":\"2012-08-31 09:54:59\",\"type\":\"ASSET.HELSINKISYMBOL\",\"displayName\":\"HELSINKI SYMBOL\"},{\"value\":\"123\",\"begin_date\":\"2012-09-01 09:01:46\",\"type\":\"ASSET.ATHENSCODE\",\"displayName\":\"ATHENS CODE\"}],\"ASSET.DISPLAYTYPE\":[{\"value\":\"COMPGE\",\"meaning\":\"Market Price Summary Composite Page\",\"id\":2000053894}],\"LOTLADDER\":[{\"not_applicable_flag\":\"N\",\"lhe_references_nda_id\":17,\"name\":\"LOT LADDER E\",\"effective_from\":\"03-SEP-12\",\"effective_to\":\"21-SEP-12\",\"cla_price_type_nda_id\":2000070109,\"value\":\"CLOSE\",\"meaning\":\"Close price\",\"begin_date\":\"01-SEP-12\"}],\"ASSET.UNDERLYINGASSET\":[{\"value\":\"72\",\"begin_date\":\"2012-09-01 10:37:59\"}],\"ASSET.QUOTATIONGROUPEDBYPSEUDOEXCH\":[{\"value\":\"BUR\",\"meaning\":\"Burgundy\",\"begin_date\":\"2012-08-30 11:47:40\"}],\"ASSET.ASSETCATEGORY\":[{\"value\":\"CCS\",\"meaning\":\"Commodity Cash\",\"id\":2124}],\"ASSET.QUOTATIONCURRENCY\":[{\"value\":\"CAD\",\"meaning\":\"Canadian Dollar\",\"begin_date\":\"2012-08-30 07:13:39\"}],\"ASSET.MIC\":[{\"value\":\"XAFR\",\"meaning\":\"ALTERNATIVA FRANCE\",\"begin_date\":\"2012-09-03 05:29:15\"}]}}"
			},
			error : function(xhr, ajaxOptions, thrownError) {
				//$.unblockUI();
				alert("error:" + thrownError);
				return false;
			},
			success : function(data) {
				if (data.flag == 0) {
					
					$(".panel-body").first().empty();										
					
					//construct page
					var page_readOnly = false, page_cne = PT.getAssetPage("FUTURESOPTION");//data.module

					asset = constructPage(page_readOnly, page_cne, $(".panel-body").first(), data);

				} else if (data.flag == 1) {
					alert(data.error.info);
				} else {
					alert("results format error");
				}
				// $.unblockUI();
				return false;
			}
		});

		//$("#ro").click(function() {
		//	if (page_readOnly) {
		//		asset.activate();
		//	}
		//});
	};
		
	panelFunction.renderRootUric = function(id, type) {
		var asset;
		
		$.ajax({
			url : "../rest/" + type + "/get",
			type : "POST",
			dataType : "json",
			data : {
				ndaid: id,
				result : "{\"flag\":0,\"properties\":{\"ASSET.RCSUNDERLYINGPRODUCT\":[{\"value\":\"46627750\",\"begin_date\":\"2012-09-01 10:46:14\"}],\"ASSET.LSEOPOL\":[{\"value\":\"XAFR\",\"meaning\":\"ALTERNATIVA FRANCE\",\"begin_date\":\"2012-09-03 05:28:53\"}],\"COMMODITY.BTUPERBARREL\":[{\"value\":\"100\"}],\"CLASSIFICATIONSCHEME\":[{\"value\":\"NMJE\",\"meaning\":\"NMJE\",\"begin_date\":\"2012-08-31 02:51:52\",\"type\":\"ASSET.ASSETROOTMAP\",\"displayName\":\"ASSET ROOT MAP\"},{\"value\":\"Y\",\"meaning\":\"Yes\",\"begin_date\":\"2012-09-03 05:29:15\",\"type\":\"ASSET.POL\",\"displayName\":\"POL\"},{\"value\":\"OPT\",\"meaning\":\"Option\",\"begin_date\":\"2012-09-03 05:42:01\",\"type\":\"ASSET.RCSASSETCLASS\",\"displayName\":\"RCS ASSET CLASS\"},{\"value\":\"3\",\"meaning\":\"Lowest priority entities, order not important.\",\"begin_date\":\"2012-08-30 05:03:45\",\"type\":\"ASSET.SEARCHRANKING\",\"displayName\":\"SEARCH RANKING\"}],\"ASSET.RIC\":[{\"value\":\"TESTCO01\",\"begin_date\":\"2012-08-30 05:03:45\"}],\"ASSET.RETIREDATE\":[{\"value\":\"01-MAR-14\"}],\"ASSET.SEDOL\":[{\"value\":\"4567653\",\"begin_date\":\"2012-09-03 05:20:47\"}],\"ASSET.PRIMARYCHAIN.RIC\":[{\"value\":\"0#LCO:\"}],\"LOCATIONS\":[{\"value\":\"AAR\",\"meaning\":\"Aarhus\",\"id\":388,\"type\":\"ASSET.PRODUCTIONLOCATION\",\"displayName\":\"PRODUCTION LOCATION\"},{\"value\":\"AAB\",\"meaning\":\"Arrabury QL\",\"id\":384,\"type\":\"ASSET.DELIVERYLOCATION\",\"displayName\":\"DELIVERY LOCATION\"}],\"ASSET.TRADES.COMMONNAME\":[{\"value\":\"Burgundy AB\"}],\"ASSET.RELATEDPAGE.RIC\":[{\"value\":\"ADD.L\"}],\"ASSET.UNDERLYINGASSET.CATEGORY\":[{\"value\":\"Alfalfa Hay\",\"meaning\":\"Alfalfa Hay\",\"id\":2784}],\"ASSET.PRIMARYCHAIN\":[{\"value\":\"67641787\",\"begin_date\":\"2012-09-01 08:46:22\"}],\"ASSET.RATINGASSET\":[{\"value\":\"Y\"}],\"TICKLADDER\":[{\"not_applicable_flag\":\"N\",\"lhe_references_nda_id\":9,\"name\":\"TICK LADDER D\",\"effective_from\":\"08-AUG-12\",\"effective_to\":\"19-SEP-12\",\"cla_price_type_nda_id\":2000070107,\"value\":\"ORDER\",\"meaning\":\"Order price\",\"begin_date\":\"01-SEP-12\"}],\"CRSUNIT\":[{\"id\":2000069955,\"value\":\"D\",\"meaning\":\"Wet Volume To Energy\",\"factor\":\"1.23\"},{\"id\":2000069959,\"value\":\"F\",\"meaning\":\"Dry Volume to Wet Volume\",\"factor\":\".4\"}],\"ASSET.ASSETSTATE\":[{\"value\":\"AC\",\"meaning\":\"Active\",\"id\":41}],\"NAME\":[{\"value\":\"10\",\"begin_date\":\"2012-08-31 09:48:14\",\"type\":\"ASSET.BRIDGEVEHICLE\",\"displayName\":\"BRIDGE VEHICLE\"},{\"value\":\"TEST Common name\",\"begin_date\":\"2012-08-30 12:01:37\",\"type\":\"ASSET.COMMONNAME\",\"displayName\":\"COMMON NAME\"},{\"value\":\"search display name\",\"begin_date\":\"2012-09-01 08:49:34\",\"type\":\"ASSET.SEARCHDISPLAYNAME\",\"displayName\":\"SEARCH DISPLAY NAME\"}],\"ASSET.TRADES\":[{\"value\":\"15882580\",\"begin_date\":\"2012-08-30 11:47:40\"}],\"COMMODITY.PRICINGUNIT\":[{\"value\":\"0.1 TONNES\",\"meaning\":\"0.1 TONNES\",\"id\":1000033100}],\"ASSET.TYPE\":[{\"value\":\"COMMODITY\"}],\"COMMODITY.BARRELSPERTON\":[{\"value\":\"6\"}],\"IDENTIFIER\":[{\"value\":\"TEST_VALUE_10\",\"begin_date\":\"2012-08-31 09:54:59\",\"type\":\"ASSET.HELSINKISYMBOL\",\"displayName\":\"HELSINKI SYMBOL\"},{\"value\":\"123\",\"begin_date\":\"2012-09-01 09:01:46\",\"type\":\"ASSET.ATHENSCODE\",\"displayName\":\"ATHENS CODE\"}],\"ASSET.DISPLAYTYPE\":[{\"value\":\"COMPGE\",\"meaning\":\"Market Price Summary Composite Page\",\"id\":2000053894}],\"LOTLADDER\":[{\"not_applicable_flag\":\"N\",\"lhe_references_nda_id\":17,\"name\":\"LOT LADDER E\",\"effective_from\":\"03-SEP-12\",\"effective_to\":\"21-SEP-12\",\"cla_price_type_nda_id\":2000070109,\"value\":\"CLOSE\",\"meaning\":\"Close price\",\"begin_date\":\"01-SEP-12\"}],\"ASSET.UNDERLYINGASSET\":[{\"value\":\"72\",\"begin_date\":\"2012-09-01 10:37:59\"}],\"ASSET.QUOTATIONGROUPEDBYPSEUDOEXCH\":[{\"value\":\"BUR\",\"meaning\":\"Burgundy\",\"begin_date\":\"2012-08-30 11:47:40\"}],\"ASSET.ASSETCATEGORY\":[{\"value\":\"CCS\",\"meaning\":\"Commodity Cash\",\"id\":2124}],\"ASSET.QUOTATIONCURRENCY\":[{\"value\":\"CAD\",\"meaning\":\"Canadian Dollar\",\"begin_date\":\"2012-08-30 07:13:39\"}],\"ASSET.MIC\":[{\"value\":\"XAFR\",\"meaning\":\"ALTERNATIVA FRANCE\",\"begin_date\":\"2012-09-03 05:29:15\"}]}}"
			},
			error : function(xhr, ajaxOptions, thrownError) {
				//$.unblockUI();
				alert("error:" + thrownError);
				return false;
			},
			success : function(data) {
				if (data.flag == 0) {
					
					$(".panel-body").first().empty();										
					
					//construct page
					var page_readOnly = false, page_cne = PT.getAssetPage("futuresOption");//data.module
					
					asset = this.constructPage(page_readOnly, page_cne, $(".panel-body").eq(2), data);
				}
			}
		});
		
	};
	
	constructPage =  function(page_readOnly, page_cne, body, data){
		
		var Content = Backbone.Model.extend({
			schema : page_cne.sections,
			type: page_cne.type
		});
		var con = new Content();
		var asset = new Backbone.Asset({
			model : con,
			readOnly : page_readOnly
		}).render();

		body.append(asset.el);
		
		//set values
		var props = data.properties, forms = asset
				.getForms(), tables = asset.getTables();

		if (forms) {
			var keys = _.keys(forms);
			_.each(keys, function(key) {
				forms[key].setValue(props, tables);
			});
		}

		if (tables) {
			var keys = _.keys(tables);
			_.each(keys, function(key) {
				if (props[key]) {
					tables[key].setValue(props[key]);
				} else {
					tables[key].setValue([]);
				}
			});
		}
		
		return asset;
	};

}.call(this));